import { _decorator, Component, KeyCode, Node } from 'cc';
import { PlayerState } from './PlayerState';
import { StateDefine } from '../../Config';
import { Sword_Skill_Controller } from '../../../Skill/SwordSkill/Sword_Skill_Controller';
const { ccclass, property } = _decorator;

@ccclass('PlayerGroundState')
export class PlayerGroundState extends PlayerState {
    onEnter() {
        super.onEnter();
    }
    onExit() {
        super.onExit();
    }
    update(deltaTime: number) {
        if(this.player.pressedKeys[KeyCode.KEY_L] && this.HashNoSword()){
            this.player.stateMgr.transit(StateDefine.AimSword);
            return;
        }
        if(this.player.pressedKeys[KeyCode.KEY_K]){
            this.player.stateMgr.transit(StateDefine.Counter);
            return;
        }
        if(this.player.pressedKeys[KeyCode.KEY_J]){
            this.player.stateMgr.transit(StateDefine.Attack);
            return;
        }
        if(!this.player.IsGroundDetected()){
            this.player.stateMgr.transit(StateDefine.Fall);
        }
        if(this.player.pressedKeys[KeyCode.SPACE] && this.player.IsGroundDetected()){
            this.player.stateMgr.transit(StateDefine.Jump);
        }
        
    }
    onDestory() { }

    canTransit(to: StateDefine): boolean {
        return true;
    }
    HashNoSword():boolean{
        if(!this.player.sword){
            return true;
        }
        this.player.sword.getComponent(Sword_Skill_Controller).ReturnSword();
        return false;
    }
}


